package com.glaciervirtualdevice.Generator;

import static com.glaciervirtualdevice.constant.DataConstant.*;
import com.glaciervirtualdevice.constant.DataConstant;

import java.util.Random;

public class TemperatureGenerator {
    private static final Random random = new Random();
    private static int minTemperature;
    private static int maxTemperature;
    private static int standardTemperature;

    // 生成温度相关信息
    private static void generateAllTemperatures() {
        // 生成 14 到 -10 之间的随机最小温度
        minTemperature = random.nextInt(LEFT_WARM_MIN_RANDOM_LINE) - RIGHT_WARM_MIN_RANDOM_LINE;

        // 生成 28 到 60 之间的随机最大温度
        maxTemperature = random.nextInt(LEFT_WARM_MAX_RANDOM_LINE) + RIGHT_WARM_MAX_RANDOM_LINE;

        // 计算稳定温度的范围
        int minStable = minTemperature + DIFFERENCE_VALUE;
        int maxStable = maxTemperature - DIFFERENCE_VALUE;

        // 确保范围有效
        if (minStable > maxStable) {
            int temp = minStable;
            minStable = maxStable;
            maxStable = temp;
        }

        // 生成稳定温度
        standardTemperature = random.nextInt(maxStable - minStable + 1) + minStable;
    }

    // 获取最小温度
    public static int getMinTemperature() {
        generateAllTemperatures();
        return minTemperature;
    }

    // 获取最大温度
    public static int getMaxTemperature() {
        generateAllTemperatures();
        return maxTemperature;
    }

    // 获取标准温度
    public static int getStandardTemperature() {
        generateAllTemperatures();
        return standardTemperature;
    }
}